import React, { PureComponent } from 'react'

/**
 * 继承PureComponent 自动比较
 * 属性或者状态 总在变化，那就不适合
 *
 * shouldComponentUpdate 方法需要手动比较
 */
export default class App extends PureComponent {
  state = {
    name: 'zhang san',
  }

  constructor() {
    super()
    console.log('constructor')
  }

  render() {
    console.log('render')
    return (
      <div>
        <h1>App</h1>
        <button onClick={() => this.setState({ name: 'li si' })}>lick</button>
        <p>{this.state.name}</p>
      </div>
    )
  }

  componentDidUpdate(prevProps, prevState, snapshot) {
    console.log('componentDidUpdate', prevProps, prevState, snapshot)
  }
}
